﻿using System;

namespace _02_CommandModel
{
    class Program
    {
        static void Main(string[] args)
        {
            // 开店前准备
            Barbecuer boy = new Barbecuer();
            Command bakeMuttonCmd1 = new BakeMuttonCommand(boy);
            Command bakeMuttonCmd2 = new BakeMuttonCommand(boy);
            Command bakeChickenWingCmd1 = new BakeChickenWingCommand(boy);
            Waiter girl = new Waiter();

            // 开门营业
            girl.SetOrder(bakeMuttonCmd1);
            girl.Notify();
            girl.SetOrder(bakeMuttonCmd2);
            girl.Notify();
            girl.SetOrder(bakeChickenWingCmd1);
            girl.Notify();

            Console.Read();
        }
    }

    // 抽象命令类
    public  abstract class Command
    {
        protected Barbecuer receiver;
        public Command(Barbecuer receiver)
        {
            this.receiver = receiver;
        }
        // 执行命令
        abstract public void ExcuteCommand();
    }

    // 考羊肉串命令
    class BakeMuttonCommand : Command
    {
        public BakeMuttonCommand(Barbecuer receiver) : base(receiver) { }

        public override void ExcuteCommand()
        {
            receiver.BakeMutton();
        }
    }
    // 烤鸡翅命令
    class BakeChickenWingCommand : Command
    {
        public BakeChickenWingCommand(Barbecuer receiver) : base(receiver) { }

        public override void ExcuteCommand()
        {
            receiver.BakeChickenWing();
        }
    }

    //烤肉串者
    public class Barbecuer
    {
        //烤羊肉
        public void BakeMutton()
        {
            Console.WriteLine("烤羊肉串!");
        }
        //烤鸡翅
        public void BakeChickenWing()
        {
            Console.WriteLine("烤鸡翅!");
        }
    }

    // 服务员
    public class Waiter
    {
        private Command command;
        // 设置订单
        public void SetOrder(Command command)
        {
            this.command = command;
        }
        // 通知执行
        public void Notify()
        {
            command.ExcuteCommand();
        }
    }
}
